//
//  CommunityViewController.m
//  SimpleTimeDemo
//
//  Created by lanou3g on 15/11/14.
//  Copyright © 2015年 王丽珍. All rights reserved.
//

#import "CommunityViewController.h"
#import "RESideMenu.h"
#import "TopicView.h"
#import "GroupView.h"
#import "MineView.h"
#import "TopicDetailViewController.h"
#import "GroupDetailViewController.h"

@interface CommunityViewController () <UIScrollViewDelegate>

@property (strong, nonatomic) IBOutlet UISegmentedControl *rightSegment;

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) TopicView *topic;
@property (nonatomic, strong) GroupView *group;
@property (nonatomic, strong) MineView *mine;

@end

@implementation CommunityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadScrollView];
    
    
#pragma mark --- 第一次进入页面进行的操作 ---
    self.topic = [[TopicView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.scrollView addSubview:self.topic];
    
    self.group = [[GroupView alloc] initWithFrame:CGRectMake(1 * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.scrollView addSubview:self.group];
    
<<<<<<< HEAD
    self.mine = [[MineView alloc] initWithFrame:CGRectMake(2 * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.scrollView addSubview:self.mine];
=======
>>>>>>> 807af8cc3ceab99a507a4b1858179a0050db9a12
    
#pragma mark --- 用通知完成cell点击的页面推出 ---
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(topicPush)
                                                 name:@"topic" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(groupPush)
                                                 name:@"group" object:nil];
    
}

- (void)topicPush {
    TopicDetailViewController *topicVC = [[TopicDetailViewController alloc] init];
    topicVC.contentid = self.topic.contentStr;
    [self.navigationController pushViewController:topicVC animated:YES];
}

- (void)groupPush {
    GroupDetailViewController *groupVC = [[GroupDetailViewController alloc] init];
    groupVC.groupid = self.group.groupStr;
    [self.navigationController pushViewController:groupVC animated:YES];
}


#pragma mark --- scrollView部分 ---
- (void)loadScrollView {
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 70, self.view.frame.size.width , self.view.frame.size.height - 70)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
<<<<<<< HEAD
    
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 3, 0);
=======
    self.scrollView.directionalLockEnabled = NO;
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);
>>>>>>> 807af8cc3ceab99a507a4b1858179a0050db9a12
    
    [self.view addSubview:self.scrollView];
}

- (IBAction)rightSegment:(UISegmentedControl *)sender {
    switch (sender.selectedSegmentIndex) {
        case 0:
            self.scrollView.contentOffset = CGPointMake(0, 0);
            break;
        case 1:
            self.scrollView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
            break;
        default:
            break;
    }
}


#pragma make --- scrollview的代理方法（滑动方法） ---
//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//    self.rightSegment.selectedSegmentIndex = self.scrollView.contentOffset.x / self.view.frame.size.width;
//}
//


#pragma mark --- 左边菜单栏弹出 ---
- (IBAction)leftBarButton:(UIBarButtonItem *)sender {
    
    [self.sideMenuViewController presentLeftMenuViewController];
}












- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)rightBarButton:(UISegmentedControl *)sender {
}
@end
